package com.jpyl.jpMedicalTreatment.view.activity.news;

import android.os.Bundle;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.jpyl.jpMedicalTreatment.R;
import com.jpyl.jpMedicalTreatment.view.activity.BaseActivity;

import butterknife.BindView;


/**
 * 新闻和广告详情界面
 * Created by 15697 on 2019/3/27.
 */

public class NewDetailsActivity extends BaseActivity {
    @BindView(R.id.web_newsDetails)
    WebView webNewsDetails;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_new_details;
    }

    @Override
    public void afterCreate(Bundle savedInstanceState) {
        mTitleTv.setText(getIntent().getStringExtra("name"));

        webNewsDetails.setWebViewClient(new WebViewClient() {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {

                return false;
            }
        });
        WebSettings webSettings = webNewsDetails.getSettings();
        // 让WebView能够执行javaScript
        webSettings.setJavaScriptEnabled(true);
        // 让JavaScript可以自动打开windows
        webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
        // 设置缓存
        webSettings.setAppCacheEnabled(true);
        // 设置缓存模式,一共有四种模式
        webSettings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
        // 支持缩放(适配到当前屏幕)
        webSettings.setSupportZoom(true);
        // 设置出现缩放工具
//        webSettings.setBuiltInZoomControls(true);
        // 将图片调整到合适的大小
        webSettings.setUseWideViewPort(true);
        // 支持内容重新布局,一共有四种方式
        // 默认的是NARROW_COLUMNS
        webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
        webSettings.setLoadWithOverviewMode(true);
        // 设置可以被显示的屏幕控制
        webSettings.setDisplayZoomControls(true);
        // 设置默认字体大小
        webSettings.setDefaultFontSize(12);

        webNewsDetails.loadUrl(getIntent().getStringExtra("url"));
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        webNewsDetails.destroy();
    }
}
